﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chowpoo.Sql;
using CourseSystem.Core.Entities;
using CourseSystem.Core.SqlServerDAL;

namespace CourseSystem.Core.BLL
{
    public class ExamStatusBLL : CommonBLL<ExamStatusInfo, ExamStatusDAL>
    {
        public static IQueryable<ExamStatusInfo> GetList(int eid, string name = "", string uid = "")
        {
            var re = GetList();
            re = re.Where(o => o.Eid == eid);
            if (!string.IsNullOrEmpty(name))
                re = re.Where(o => o.StudentInfo.StuName.Contains(name));
            if (!string.IsNullOrEmpty(uid))
                re = re.Where(o => o.StudentInfo.Uid == uid);
            return re;
        }

        public static bool SetEnforceSubmitAll(int eid)
        {
            using (var dal = new ExamStatusDAL())
            {
                return dal.SetEnforceSubmitAll(eid);
            } 
        }

        public static bool SetWarnAll(int eid)
        {
            using (var dal = new ExamStatusDAL())
            {
                return dal.SetWarnAll(eid);
            }
        }

        public static ExamStatusInfo Get(int eid,int uid)
        {
            using (var dal = new ExamStatusDAL())
            {
                var re = dal.SelectSingle(o => o.Eid == eid&&o.StudentId==uid);
                return re;
            }
        }

        public static ExamStatusInfo Get(int id)
        {
            using (var dal = new ExamStatusDAL())
            {
                var re = dal.SelectSingle(o => o.Id == id);
                return re;
            }
        }


        public static bool Del(int id)
        {
            using (var dal = new ExamStatusDAL())
            {
                return dal.Delete(o => o.Id == id) != null;
            }
        }

    }
}
